package sc.util;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import sc.writable.IntermediateData;
import sc.writable.StockSummary;

/**
 * Data generated when reading the output of the summary.
 * 
 * @author Quentin Rossé
 *
 */
public class DisplayData {

	/**
	 * stocks main informations (displayed in the main frame)
	 */
	private ArrayList<StockSummary> stocks = 
		new ArrayList<StockSummary>();
	
	/**
	 * stocks detailed informations (displayed in the detail frame)
	 */
	private TreeMap<String, List<IntermediateData>> details = 
		new TreeMap<String, List<IntermediateData>>();
	
	/**
	 * adds a detailed information to a stock. If the stock doesn't exist
	 * yet, it will be added to the stock list.
	 * 
	 * @param stockSummary the stock and his informations
	 * @param detail the detailed informations to add
	 */
	public void addDetail(StockSummary stockSummary, IntermediateData detail){
		if(! stockExists(stockSummary.getStock())){
			details.put(stockSummary.getStock(), new LinkedList<IntermediateData>());
			stocks.add(new StockSummary(stockSummary));
		}
		details.get(stockSummary.getStock()).add(new IntermediateData(detail));
	}
	
	public boolean stockExists(String stock){
		return details.containsKey(stock);
	}

	public List<StockSummary> getStocks() {
		return stocks;
	}

	public Map<String, List<IntermediateData>> getDetails() {
		return details;
	}
	
}
